//
//  YWEquUseMethodAndRangeTableViewController.m
//  maintain
//
//  Created by Kyo on 16/11/2.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWEquUseMethodAndRangeTableViewController.h"
#import "UIColor+CustomColors.h"
#import "UIScrollView+EmptyDataSet.h"

#import "UITableView+FDTemplateLayoutCell.h"
#import "YWUseMethodAndRangeCell.h"

#import "YWEquipmentManager.h"
#import "YWEquipmentUseMenthod.h"
#import "YWEquipmentUseRange.h"

@interface YWEquUseMethodAndRangeTableViewController ()<DZNEmptyDataSetDelegate, DZNEmptyDataSetSource>
@property (nonatomic, strong) NSMutableArray *titleDataSource;
@property (nonatomic, strong) NSMutableArray *contentDataSource;
@end

@implementation YWEquUseMethodAndRangeTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"使用方法和范围";
    
    [self setupData];
    
    [self.tableView registerClass:[YWUseMethodAndRangeCell class] forCellReuseIdentifier:YWUseMethodAndRangeCellIdentifier];
    self.tableView.backgroundColor = [UIColor customBackgroudColor];
    self.tableView.separatorColor = [UIColor customLineColor];
    self.tableView.tableFooterView = [[UIView alloc] init];
    self.tableView.emptyDataSetDelegate = self;
    self.tableView.emptyDataSetSource = self;
    self.tableView.estimatedRowHeight = 44.0f;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
}

- (void)setupData{
    _titleDataSource = [NSMutableArray array];
    _contentDataSource = [NSMutableArray array];
    NSString *equipmentTypeName = [[YWEquipmentManager shareManager] equipmentTypeNameWithTypeId:_equipmentTypeId];
    [_titleDataSource addObject:[NSString stringWithFormat:@"%@使用方法",equipmentTypeName]];
    [_titleDataSource addObject:[NSString stringWithFormat:@"%@使用范围",equipmentTypeName]];
    
    YWEquipmentUseMenthod *useMethod = [[YWEquipmentManager shareManager] useMenthodWithEquipmentTypeId:_equipmentTypeId];
    if (useMethod.content.length) {
        [_contentDataSource addObject:useMethod.content];
    }else{
        [_contentDataSource addObject:@"无"];
    }
    
    YWEquipmentUseRange *useRange = [[YWEquipmentManager shareManager] useRangeWithEquipmentTypeId:_equipmentTypeId];
    if (useRange.content.length) {
        [_contentDataSource addObject:useRange.content];
    }else{
        [_contentDataSource addObject:@"无"];
    }
}

#pragma mark - Table view data source
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    return  [tableView fd_heightForCellWithIdentifier:YWUseMethodAndRangeCellIdentifier cacheByIndexPath:indexPath configuration:^(YWUseMethodAndRangeCell *cell) {
//        cell.title = _titleDataSource[indexPath.row];
//        cell.content = _contentDataSource[indexPath.row];
//    }];
//}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _contentDataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YWUseMethodAndRangeCell *cell = [tableView dequeueReusableCellWithIdentifier:YWUseMethodAndRangeCellIdentifier];
    cell.title = _titleDataSource[indexPath.row];
    cell.content = _contentDataSource[indexPath.row];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
